package org.paradise.controller;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.paradise.dao.ShoppingXsDao;
import org.paradise.pojo.ShoppingXs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/ShoppingXs")
public class ShoppingXsController {

    @Autowired
    private ShoppingXsDao shoppingXsDao;

    //查询所有销售数据调用的方法
    @RequestMapping("/list")
    @ResponseBody
    public Map<String,Object> list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit, ShoppingXs condition) throws Exception{
        Map<String,Object> map = new HashMap<>();
        Page<ShoppingXs> pager = PageHelper.startPage(page,limit);
        List<ShoppingXs> list = shoppingXsDao.getList(condition);
        map.put("count",pager.getTotal());  //条数
        map.put("data",list);   //数据
        map.put("code",0);   //状态
        map.put("msg","");   //返回的日志
        return map;
    }

    //批量删调用的方法
    @RequestMapping(value = "/batchDelete",method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> batchDelete(Integer[] id) throws Exception{
        Map<String,Object> map = new HashMap<String,Object>();
        shoppingXsDao.batchDelete(id);
        map.put("result",true);
        return map;
    }

}
